package com.luhaoran.hrm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luhaoran.hrm.entity.Employee;
import com.luhaoran.hrm.mapper.IEmployeeMapper;
import com.luhaoran.hrm.model.ApiEmployeePage;
import com.luhaoran.hrm.service.IEmployeeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl extends ServiceImpl<IEmployeeMapper, Employee>
        implements IEmployeeService {


    @Override
    public IPage<Employee> getPage(ApiEmployeePage apiEmployeePage) {
        Page<Employee> page = new Page<>(apiEmployeePage.getPageIndex(), apiEmployeePage.getPageSize());
        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        if (apiEmployeePage.getEmployeeId() != null) {
            employeeQueryWrapper.eq("id", apiEmployeePage.getEmployeeId());
        }

        if (apiEmployeePage.getDepartmentId() != null) {
            employeeQueryWrapper.eq("department_id", apiEmployeePage.getDepartmentId());
        }

        if (apiEmployeePage.getEmployeeName() != null) {
            employeeQueryWrapper.like("name", apiEmployeePage.getEmployeeName());
        }
        if (apiEmployeePage.getSex() != null) {
            employeeQueryWrapper.eq("sex", apiEmployeePage.getSex());
        }
        employeeQueryWrapper.between("age",20,30);
        return page(page, employeeQueryWrapper);
    }
}

